<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------
// 应用公共文件
/**
 * @Desc 导出到excel表格
 *
 * @param array  $data      要导出的数据，二维数组，首个元素为标题
 * @param string $file_name 文件名
 */
function exportExcel($data, $file_name = '统计表')
{
    header("Content-type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
    header('Content-Disposition: attachment; filename="' . $file_name . '.xlsx"');
    header('Cache-Control: must-revalidate');
    header('Expires: 0');
    header('Pragma: public');
    $table_data = '<table border="1">';
    foreach ($data as $line) {
        $table_data .= '<tr>';
        foreach ($line as $key => &$item) {
            if ($key == 'idcard') {
                $table_data .= '<td style="vnd.ms-excel.numberformat:@ ">' . $item . '</td>';
            } else {
                $table_data .= '<td>' . $item . '</td>';
            }
        }
        $table_data .= '</tr>';
    }
    $table_data .= '</table>';
    echo $table_data;
    die();
}

/**
 * @Desc 二维数组中是否存在指定的元素
 *
 * @param string $value 要查找的元素
 * @param array  $array 数组
 *
 * @return bool
 */
function deep_in_array($value, $array)
{
    foreach ($array as $item) {
        if (!is_array($item)) {
            if ($item == $value) {
                return true;
            }
            continue;
        }
        if (in_array($value, $item, true)) {
            return true;
        }
        if (deep_in_array($value, $item)) {
            return true;
        }
    }
    return false;
}